{extend name="layout/base"}

{block name="content"}

<form class="layui-form">
    <div class="layui-container">
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" name="username" placeholder="请输入用户名" lay-verify="required">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="" class="layui-form-label">密码</label>
            <div class="layui-input-block">
                <input type="password" class="layui-input" name="pwd1" placeholder="请输入密码" lay-verify="required">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="" class="layui-form-label">确认密码</label>
            <div class="layui-input-block">
                <input type="password" class="layui-input" name="pwd2" placeholder="请再次输入密码" lay-verify="required">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-inline" style="margin-left: 100px">
                <button class="layui-btn  layui-text-center" lay-submit lay-filter="submit">提交</button>
            </div>
        </div>
    </div>
</form>

<script>
    layui.use(['jquery', 'form', 'layer', 'formSelects'], function ($, form, layer, formSelects) {
        formSelects.render('roleId');
        form.on('submit(submit)', function (obj) {
            var roleId = formSelects.value('roleId', 'valStr');
            obj.field.roleId = roleId;

            $.ajax({
                type: "post",
                url: "{:url('manager/add')}",
                dataType: 'json',
                data: obj.field,
                success: function (data) {
                    if (data.code == 0) {
                        layer.msg(data.msg, {icon: 5});
                        parent.location.href = "{:url('manager/lists')}"
                    } else {
                        layer.msg(data.msg, {icon: 6});
                    }
                },
                error: function () {
                    layer.msg('请求错误', {icon: 6});
                }
            });

            return false;
        })
    });

</script>
{/block}